---
title: "COVID-19 Nepal"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
vertical_layout: fill
---
```{r setup, include=FALSE}
### DEFINE LIBRARIES ---
library("flexdashboard")
library("ggplot2")
library("plotly")
# DATA CURATED FROM DATA RELEASED (UPDATED DAILY) FROM
# GOVT. OF NEPAL, MINISTRY OF HEALTH AND POPULATION
# HEALTH SECTOR RESPONSE TO CORONAVIRUS DISEASE (COVID-19)
# URL: https://drive.google.com/drive/folders/1QhLMbT76t6Zu1sFy5qlB5aoDbHVAcnHx
### DEFINE FILE ---
dir.data <- file.path("data")
file.dat <- file.path(dir.data, "data_total.tsv")
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
test_color <- "#4292c6"
confirmed_color <- "#b15928"
active_color <- "#ff7f00"
recovered_color <- "#33a02c"
death_color <- "#e31a1c"
### LOAD DATA ---
dat <- read.delim(file.dat, header=TRUE, stringsAsFactors=FALSE)
dat$date <- as.Date(dat$date, format = "%m/%d/%y")
### FUNCTION: num_changes() ---
num_changes <- function(x){
y <- numeric()
y[1] <- x[1]
for(i in 2:length(x)){
y[i] <- x[i] - x[i-1]
}
return(y)
}
### CALCULATE ACTIVE INFECTION, NEW TESTS, NEW POITIVES, NEW DEATH, NEW RECOVERED ---
dat$active_case <- dat$total_positive - dat$total_recovered
dat$new_tested <- num_changes(dat$total_test)
dat$new_positive <- num_changes(dat$total_positive)
dat$new_death <- num_changes(dat$total_death)
dat$new_recovered <- num_changes(dat$total_recovered)
### LATEST INFO ---
total_test <- dat$total_test[nrow(dat)]
total_positive <- dat$total_positive[nrow(dat)]
active_case <- dat$active_case[nrow(dat)]
total_recovered <- dat$total_recovered[nrow(dat)]
total_death <- dat$total_death[nrow(dat)]
```
Summary
=======================================================================
Row
-----------------------------------------------------------------------
### Total Test Conducted {.value-box}
```{r}
valueBox(value = paste(format(total_test, big.mark = ","), "", sep = " "),
caption = "Total Test Conducted",
icon = "fas fa-vial",
color = test_color)
```
### Positive {.value-box}
```{r}
valueBox(value = paste(format(total_positive, big.mark = ","), "", sep = " "),
caption = "Positive Cases",
icon = "fas fa-user-md",
color = confirmed_color)
```
### active {.value-box}
```{r}
valueBox(value = paste(format(active_case, big.mark = ","), "", sep = " "),
caption = "Active Cases",
icon = "fas fa-ambulance",
color = active_color)
```
### recovered {.value-box}
```{r}
valueBox(value = paste(format(total_recovered, big.mark = ","), "", sep = " "),
caption = "Recovered Cases", icon = "fas fa-heartbeat",
color = recovered_color)
```
### death {.value-box}
```{r}
valueBox(value = paste(format(total_death, big.mark = ","), "", sep = " "),
caption = "Death Cases",
icon = "fas fa-bolt",
color = death_color)
```
Row
-----------------------------------------------------------------------
### Total Positive Cases in Nepal
```{r}
p1 <- ggplot(dat, aes(x=date, y=total_positive)) +
geom_point(color=confirmed_color, alpha=1, size=2) +
geom_line(color=confirmed_color, alpha=1, size=1)+
theme(
axis.text.x = element_text(size = 15, color="#000000"),
axis.text.y = element_text(size = 15, color="#000000"),
axis.title = element_text(size = 15, color="#000000"),
plot.title = element_text(size = 15, color="#000000", hjust=0.5),
panel.grid.major.y = element_line(size=0.5, color="#BDBDBD"),
panel.grid.minor.y = element_line(size=0.25, color="#BDBDBD"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.ticks = element_line(size=0.4, color="#000000"),
strip.text = element_text(size=10, color="#000000"),
strip.background = element_rect(fill="#FFFFFF", color="#FFFFFF"),
panel.background = element_rect(fill="#FFFFFF", color="#FFFFFF"),
axis.line.x = element_line(size = 1.5, color="#000000"),
axis.line.y = element_blank(),
legend.text = element_text(size = 10, color="#000000"),
legend.title = element_blank(),
legend.key.size = unit(0.5, "cm"),
legend.position = "none") +
ylab("Total Positive Cases") +
xlab("Date") +
ggtitle("")
plotly::ggplotly(p1)
```
Row {data-width=400}
-----------------------------------------------------------------------
### RT-PCR Tests Conducted
```{r}
p2 <- ggplot(dat, aes(x=date, y=total_test)) +
geom_point(color=test_color, alpha=1, size=2) +
geom_line(color=test_color, alpha=1, size=1)+
theme(
axis.text.x = element_text(size = 15, color="#000000"),
axis.text.y = element_text(size = 15, color="#000000"),
axis.title = element_text(size = 15, color="#000000"),
plot.title = element_text(size = 15, color="#000000", hjust=0.5),
panel.grid.major.y = element_line(size=0.5, color="#BDBDBD"),
panel.grid.minor.y = element_line(size=0.25, color="#BDBDBD"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.ticks = element_line(size=0.4, color="#000000"),
strip.text = element_text(size=10, color="#000000"),
strip.background = element_rect(fill="#FFFFFF", color="#FFFFFF"),
panel.background = element_rect(fill="#FFFFFF", color="#FFFFFF"),
axis.line.x = element_line(size = 1.5, color="#000000"),
axis.line.y = element_blank(),
legend.text = element_text(size = 10, color="#000000"),
legend.title = element_blank(),
legend.key.size = unit(0.5, "cm"),
legend.position = "none") +
ylab("Total RT-PCR Test Conducted") +
xlab("Date") +
ggtitle("")
plotly::ggplotly(p2) %>% layout(hoverlabel=list(bgcolor="#FFFFFF"))
```
### Data
```{r}
dtbl <- dat %>%
dplyr::select(Date=date,
'Total Test'=total_test,
'Total Positive'=total_positive,
'Active Cases'=active_case,
'Total Recovered'=total_recovered,
'Total Death'=total_death)
dtbl$Date <- as.Date(dtbl$Date, format = '%Y/%m/%d')
dtbl <- dtbl[order(dtbl$Date, decreasing = TRUE),]
dtbl %>%
DT::datatable(rownames = FALSE,
options = list(searchHighlight = TRUE,
pageLength = 20))
```